package net.xi.dmhome.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: jxhu
 * @Description:
 * @Date Created in 2021-02-06 11:29
 * @Modified By:
 */
@Slf4j
@Component
public class TimeHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill	");
// setFieldValByName(String fieldName, Object fieldVal, MetaObject metaObject
        this.setFieldValByName("createtime",new Date(),metaObject);
        this.setFieldValByName("updatetime",new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill	");
        this.setFieldValByName("updatetime",new Date(),metaObject);

    }
}
